package com.example.common.utils;

public enum  ResponseCode {
    SUCCESS(200,"操作成功!"),
    FAILURE(201,"操作失败"),
    /**系统相关的错误码：5开头**/
    //ERROR(500,"系统异常，请稍后重试"),
    BAD_REQUEST(400, "请求数据格式不正确!"),
    UNAUTHORIZED(401, "登录凭证过期!"),
    FORBIDDEN(403, "没有访问权限!"),
    NOT_FOUND(404, "请求的资源找不到!"),
    ERROR(500, "服务器内部错误!"),
    SERVICE_UNAVAILABLE(503, "服务器正忙，请稍后再试!");

    private final int code;

    private final String message;

    ResponseCode(int code, String message){
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    // 静态方法，用于查找匹配的枚举实例
    public static String findByCode(int code) {
        for (ResponseCode re : ResponseCode.values()) {
            if (re.getCode()==code) {
                return re.getMessage();
            }
        }
        return "未知错误"; // 如果没有找到匹配的枚举，返回null
    }


}
